//#include "stdafx.h"
#include "base_common_str.h"

void  _base_trim_left( char_t * lpszStr )
{
	if( lpszStr == NULL )
	{
		return;
	}

	size_t len = _tcslen( lpszStr );
	for( size_t i = 0; i < len; i++ )
	{
		if( lpszStr[i] != _T(' ') )
		{
			lpszStr = &lpszStr[i];
			break;
		}
	}
}
void  _base_trim_right( char_t * lpszStr )
{
	if( lpszStr == NULL )
	{
		return;
	}
	size_t len = _tcslen( lpszStr );
	size_t i;
	for( i = len-1; i >= 0; i++ )
	{
		if( lpszStr[i] != ' ' )
		{
			break;
		}
	}
	lpszStr[i+1] = '\0';
}
int32 _base_find_str( cstr_t lpszSourceStr, cstr_t lpszFindStr, bool isCaseSensitive )
{
	size_t nSourceLen    = _tcslen( lpszSourceStr );
	size_t nContainedLen = _tcslen( lpszFindStr );
	if( nContainedLen > nSourceLen )
	{
		return -1;
	}
	for( size_t i = 0; i < nSourceLen && nSourceLen-i >= nContainedLen; i++ )
	{
		if( isCaseSensitive == false )
		{
			if( _tcsnicmp( &lpszSourceStr[i], lpszFindStr, _tcslen(lpszFindStr) ) == 0 )
			{
				return i;
			}
		}
		else
		{
			if( _tcsncmp( &lpszSourceStr[i], lpszFindStr, _tcslen(lpszFindStr) ) == 0 )
			{
				return i;
			}
		}
	}
	return -1;
}
